<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
//用try-catch
try {
    //模拟错误-方式1-用JSON.parse,自动throw new Error
    /*
    let s = '{username: "zs"}'
    let o = JSON.parse(s)
    */
    //https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Error
    //模拟错误-方式2-用默认Error
    // throw new Error('产生了错误')
    //模拟错误-方式3.1-用自定义错误
    /*
    function MyError(status){
        this.response = {status}
    }
    throw new MyError(404)
    */
    //模拟错误-方式3.2-用自定义错误+匿名立即执行函数
    throw new (function (status){
        this.response = {status}
    })(500)
}catch(e){
    // console.log(e)
    //默认错误e= {message, stack}
    //预期错误e= {response: {status: 404}}
    console.dir(e)
}

console.log(123)
</script>
</html>